package cn.tx.util;

import cn.tx.dao.ClazzDao;
import cn.tx.dao.EmpDao;
import cn.tx.dao.GradeDao;
import cn.tx.model.Clazz;
import cn.tx.model.Emp;
import cn.tx.model.Grade;
import cn.tx.page.Page;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RunWith(SpringJUnit4ClassRunner.class)// 添加spring测试方案
@ContextConfiguration("/config/spring/applicationContext.xml")// 指定spring配置文件位置
public class MyBatisTest {

    @Autowired
    private GradeDao gradeDao;
    @Autowired
    private EmpDao empDao;
    @Test
    public void testInsert2() {
        Emp m = new Emp();
        m.setName("张三");
        m.setSex("男");
        String strDate = "2022-07-06";

        // SimpleDateFormat lsdStrFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat lsdStrFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date d1 = lsdStrFormat.parse(strDate);

            m.setDateone(d1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        empDao.addEmp(m);
    }
    //
    @Test
    public void testInsert() {
        Grade c = new Grade();
        c.setName("2022");
        c.setYname("测试组");
        gradeDao.addGrade(c);
    }
    @Test
    public void testSelect1() {

        Map<String,Object> querymap = new HashMap<String,Object>();
        querymap.put("name","%张三%");
        querymap.put("offset", 10);
        querymap.put("pageSize", 10);
        List<Emp> list = empDao.findList(querymap);
        for(Emp c:list){
            System.out.println(c.getId()+"---"+c.getName());
        }
    }
    @Test
    public void testUpdate() {
        Grade c = new Grade();
        c.setId(27L);
        c.setName("2022-修改");
        c.setYname("测试组程序修改");
        gradeDao.UpdateGradeById(c);

    }
    @Test
    public void testDelete() {
        gradeDao.delete("27");
    }
    @Test
    public void testSelect() {
        List<Grade> list =  gradeDao.findAll();
        for(Grade c:list){
            System.out.println(c.getYname()+"---"+c.getName());
        }
    }

}
